# author: Han Zhang
#########################################################################################
######################## Figure 4 #################################


library(ggplot2)

DPI = 300
WIDTH = 7
UNIT = "in"



df3 <- read.csv('firststage_c1_text_image_precision_recall.csv', sep = ',', stringsAsFactors = F)
df3$f1 = with(df3, 2 * precision * recall /(precision + recall))



labels = c("Image", "Text","Combined")


ggplot(df3, aes(x = recall, y = precision, colour = label, linetype = label)) +
  geom_line(size = 2)+
  scale_color_manual (values = c(  "grey20", "grey50", "black"),  labels = labels) + 
  scale_linetype_manual(values = c("dotted", "dotdash", "solid"), labels = labels) +
  guides(colour = guide_legend(title = "Classifier"), linetype = guide_legend(title = "Classifier")) +
  theme_bw() +
  theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
        panel.background = element_blank(), axis.line = element_line(colour = "black")) +
  theme(axis.text = element_text(size = 20, colour = "black"),
        axis.title = element_text(size = 28, colour = "black"),
        plot.title = element_text(size = 20, colour = "black")) +
  theme(legend.text=element_text(size= 24),
        legend.key.width = unit(3, "line"),
        legend.key.height = unit(2, "line"),
        legend.title=element_text(size= 24)) +
  theme(legend.position = c(0.24, 0.2)) +
  theme(legend.text.align = 0) +
ylim (0,1)


ggsave("firststage_c1_text_image_precision_recall.pdf",
dpi = DPI, width = WIDTH, height = WIDTH / 1.2, units = UNIT)
